package com.ratp.expertisetechnique;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.ratp.bean.Expertise;
import com.ratp.bean.UtilsBean;
import com.ratp.composants.CustomTextWatcher;

public class Obligations_Reglementaire extends Activity {
	private RadioButton ButtonOuiControlo;
	private RadioButton ButtonNonControlo;
	private RadioGroup radioGroupControlo;
	private RadioButton ButtonOuiDrir;
	private RadioButton ButtonNonDrir;
	private EditText editCommentaireDrireObligation;
	private EditText editCommentaireControloObligation;
	private RadioGroup radioGroupDrir;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.obligations_reglementaire);
		initVariables();
		initEcouteurs();
	}
	private void initVariables() {

		ButtonOuiDrir = (RadioButton) findViewById(R.id.ButtonOuiDrir);
		ButtonNonDrir = (RadioButton) findViewById(R.id.ButtonNonDrir);
		radioGroupDrir = (RadioGroup) findViewById(R.id.radioGroupDrir);

		ButtonOuiControlo = (RadioButton) findViewById(R.id.ButtonOuiControlo);
		ButtonNonControlo = (RadioButton) findViewById(R.id.ButtonNonControlo);
		radioGroupControlo = (RadioGroup) findViewById(R.id.radioGroupControlo);

		editCommentaireDrireObligation = (EditText) findViewById(R.id.editCommentaireDrireObligation);
		editCommentaireControloObligation = (EditText) findViewById(R.id.editCommentaireControloObligation);

		Expertise expertise = UtilsBean.getExpertiseInstance();

		ButtonOuiDrir.setChecked(expertise.isVisiteDrire());
		ButtonNonDrir.setChecked(!expertise.isVisiteDrire());
		
		editCommentaireDrireObligation.setText(expertise.getVisiteDrireCom());

		if(expertise.isVisiteControl()){
			ButtonOuiControlo.setChecked(true);
			ButtonNonControlo.setChecked(false);
		}
		else{
			ButtonOuiControlo.setChecked(false);
			ButtonNonControlo.setChecked(true);
		}
		
		editCommentaireControloObligation.setText(expertise.getVisiteControloCom());
	}

	private void initEcouteurs() {
		radioGroupDrir.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
		{
			public void onCheckedChanged(RadioGroup radioGroupDrir, int checkedId)
			{
				UtilsBean.getExpertiseInstance().setVisiteDrire(ButtonOuiDrir.isChecked());
			}
		});
		radioGroupControlo.setOnCheckedChangeListener(new OnCheckedChangeListener() 
		{
			public void onCheckedChanged(RadioGroup group, int checkedId)
			{
				if (ButtonOuiControlo.isChecked())
				{
					UtilsBean.getExpertiseInstance().setVisiteControl(true);
				}
				else if(ButtonNonControlo.isChecked())  {
					UtilsBean.getExpertiseInstance().setVisiteControl(false);
				}
			}
		});
		editCommentaireDrireObligation.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setVisiteDrireCom(s.toString());
			}
		});
		editCommentaireControloObligation.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setVisiteControloCom(s.toString());
			}
		});
	}
}

